aboutsummaryrefslogtreecommitdiff
path: root/pages/logs/[directory].tsx
blob: 59875f105422123be587e9eb3411efd4c3ac6172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { GetStaticProps, GetStaticPropsContext } from 'next';
import React, { FC } from 'react';
import { getPosts, getMarkdown, Post, getPostFromDirectory } from '../../utils/Posts';
import Markdown from '../../components/Markdown';
import DefaultPage from '../../templates/Default';

interface Props {
  post: Post;
  markdown: string;
}

const Page : FC<Props> = ({ post, markdown }) => {
    const { lastUpdated } = post.meta;

    return (
      <>
        <DefaultPage
          path={"/logs/" + post.directory}
          lastUpdated={lastUpdated}
        >
        <Markdown
          md={markdown}
        />
        </DefaultPage>
      </>
    );
}

export default Page;

export const getStaticProps: GetStaticProps = async (
    context: GetStaticPropsContext
  ) => {
    const directory = context.params!.directory as string;

    const post = await getPostFromDirectory(directory);

    const markdown = await getMarkdown(post);

    return {
      props: { post, markdown },
    }
}

export async function getStaticPaths() {
  const posts = await getPosts();

  const paths = posts.map((post) => {
    return {
      params: {
        directory: post.directory
      }
    };
  });

  return {
    paths,
    fallback: false
  };
}